import csv



train_file = "/home/zuwenqiang/data/MedFMC/MedFMC_train/endo/endo_train.csv"
output_train = "tools/convert/train.txt"

# test_file = "tools/convert/test.csv"
# output_test = "tools/convert/test.txt"

with open(train_file, "r") as file:
    reader = csv.reader(file)
    next(reader)  # 跳过第一行标题

    with open(output_train, "w") as output:
        for row in reader:
            image_id = row[1]
            categories = [str(val[0]+'') for i, val in enumerate(row[3:], start=0)]
            categories[-1] = categories[-1][0]
            output.write(f"{image_id} {'    '.join(categories)}\n")


# with open(test_file, "r") as file:
#     reader = csv.reader(file)
#     next(reader)  # 跳过第一行标题

#     with open(output_test, "w") as output:
#         for row in reader:
#             row=row.split(',')
#             image_id = row[0]
#             categories = [str(i) for i, val in enumerate(row[1:], start=0) if float(val) == 1.0]
#             output.write(f"{image_id}.jpg {' '.join(categories)}\n")